****** run all for mover analysis

clear all
set more off

*project directory
global proj "/Users/hanyang/tu2"

*specific path
global dataRoot  	"${proj}/Data/Clean"

global stataRoot 	"${proj}/Code/3_Analysis"	//stata codes

global outDir 	 	"${proj}/Output"	
global outDataDir 	"${outDir}/Data"		//store some small summary level data for output purposes


global figGeoDebt    	"${outDir}/Figures"	

qui do "${stataRoot}/00_config.do"





* load individual level data, winsorize balance variables, and aggregate to cz level
* need to set geographic level to individual
do "${stataRoot}/02_indi_to_cz.do"

* merge financial distress measures with demographics
* produce summary statistics and maps
* need to set geographic level to cz
do "${stataRoot}/03_sumstats.do"

* decompose variation to within vs between
* need to set geographic level to cz
do "${stataRoot}/04_decom_variation.do"


* rank stability of key outcome variables
* need to set geographic level to cz
do "${stataRoot}/05_rank_stability.do"


* decay pattern of stock of collection and credit card
do "${stataRoot}/06_decay_plots.do"


*** the following are for mover event study

* construct mover delta
* we run this for different geographic level
do "${stataRoot}/07_mover_delta.do"


* mover event study
* we run this for different geographic level and sample restrictions
do "${stataRoot}/08_mover_event_study.do"


* aggregate event study coefficients and prepare tables to report results
do "${stataRoot}/09_event_study_tables.do"


* numbers of non movers to compute delta
* run this for different geographic levels
do "${stataRoot}/10_mover_sum_stats.do"


* decompose place vs person using a two-way fixed effect model
* also run the model across bootstrap data
do "${stataRoot}/11_two_way_fe.do"


* aggregate two-way fixed effect results and prepare table
do "${stataRoot}/12_two_way_fe_tables.do"


* run two-way fixed effect model at state level to estimate state place effect 
* prepare data to select key correlates in R
do "${stataRoot}/13_state_level_correlates.do"

* Run LASSO in R 
* select correlates with each state level place effects of financial distress measures
// "${stataRoot}/14_place_vs_person_lasso.R"


* take variable selection outputs from R to project place effect on correlates
do "${stataRoot}/15_place_vs_person_project.do"


* compute number of movers in each origin/destination cz and produce maps
do "${stataRoot}/16_maps_movers.do"

* binned scatter plots of bankruptcy rate by incopme
do "${stataRoot}/17_bankruptcy_income.do"



